package com.breeze.components.core.util.json.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneId;

/**
 * @author breeze
 */
public class LocalDateTimeToSecondIntegerSerializer extends JsonSerializer<LocalDateTime> {

  @Override
  public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers)
      throws IOException {
    long epochTime = value.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() / 1000;
    gen.writeNumber(epochTime);
  }
}
